package com.xzy.simple;

import lombok.Getter;
import lombok.ToString;
import org.springframework.context.ApplicationEvent;

/**
 * 自定义事件
 *
 * @author xzy.xiao
 * @date 2022/10/8  18:57
 */
@Getter
@ToString
public class UserEvent extends ApplicationEvent {

    // ==================== field ====================

    /**
     * 事件类型
     */
    private final EventType eventType;
    /**
     * 发起事件的用户
     */
    private final User eventUser;
    /**
     * 事件创建时间
     */
    private final Long createTime;

    // ==================== constructor ====================

    public UserEvent(EventType eventType, User eventUser) {
        super(eventUser);
        this.eventType = eventType;
        this.eventUser = eventUser;
        this.createTime = System.currentTimeMillis();
    }

    public enum EventType {
        /**
         * 新增
         */
        INSERT,
        /**
         * 删除
         */
        DELETE,
        /**
         * 编辑
         */
        UPDATE
    }
}
